﻿package shapes.shapes2D.curves 
{
	import flash.geom.Point;
	/**
	 * @author Nicolas Barradeau
	 */
	public class QuadraticPath
	{
		
		public function QuadraticPath() {}
		
		static private var _precision:Number = .01;
		static public function compute( handles:Vector.<Point>, loop:Boolean = false ):Vector.<Point>
		{
		
		
			//output values
			var tmp:Vector.<Point> = new Vector.<Point>();
		
			var p0:Point = handles[ 0 ];
			var p1:Point = handles[ 1 ];
			var p2:Point = handles[ 2 ];
			var p3:Point = handles[ 3 ];
			var x:Number, y:Number, t:Number;
			
			for( t = 0; t < 1; t+=_precision )
			{
				
				x = p0.x * Math.pow( (1 - t), 3); 
				x += 3 * p1.x * t * Math.pow( (1 - t), 2 );
				x += 3 * p2.x * ( t * t ) * ( 1 - t);
				x += p3.x * ( t*t*t );
				
				y = p0.y * Math.pow( (1 - t), 3); 
				y += 3 * p1.y * t * Math.pow( (1 - t), 2 );
				y += 3 * p2.y * ( t * t ) * ( 1 - t);
				y += p3.y * ( t * t * t );
				
				tmp.push( new Point( x,y ) );
			}
			
			return tmp;
		
		}
		
		static public function get precision():Number { return _precision; }
		
		static public function set precision(value:Number):void 
		{
			_precision = value;
		}
	}

}